
define(['vue','config','common'],function(Vue,config,utils){
	'use strict';

	var forgetPasswordView=new Vue({
		el:'#app',
		data:{
			role : 'E享会员',
			recommendPerson:'',
			userID:4,					//用户编号
			customerID:5,				//商家ID

			userTyptId:'',				//用户类型id
			phone:'',					//手机号码
			phoneCode:'',				//验证码

			secondOfDelay : 120000 ,
			secondLeftOfDelay : 0,

			submitBtn: false
		},
		created:function(){
			var _this=this;

			//获取用户类型
			/*utils.initAjax('user/getUserType',null,'POST',function(res){
				//console.log(res)
				_this.userID = res.data[1].id;
				_this.customerID = res.data[2].id;
			})*/

		},
		methods:{
			/*SelectRole:function(event){
				$('.Pop_BJ').show();
			},
			Role:function(event){
				this.role=$(event.target).text();
				$('.Pop_BJ').hide();
			},*/
			getVeryCode:function(){
				//var role = $('#role').text();
				var phone = $('#phone').val();

				if($.trim(phone) === ""){
                    utils.appAlert('手机号码不能为空',function(){
                    	$('#phone').focus();
                    	$('.framework7-root').css({'overflow-y':'scroll'});
                    });
                    return;
				}

				if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
                    utils.appAlert('请输入正确的手机号码',function(){
                    	$('#phone').focus();
                    	$('.framework7-root').css({'overflow-y':'scroll'});
                    });
                    return;
				}

				var _this=this;
				utils.initAjax('user/isEixt',{
					phone: phone
				},'POST',function(res){
					if(res.msg === "false"){
						utils.appAlert('此用户不存在');
					}else{
						var data = {
							phone: phone,
							codeType: 8,
							smsType: 1
						};
						utils.initAjax('verify/sendPhoneCode',data,'POST',function(res){
					        utils.appAlert('请查收你的短信',function(){
					        	_this.sendVerifyCodeTimer();
					        });
					        $(".verification").attr('disabled','true');
						})
					}
				})

				
			},

			/*getvoiceMessage:function(){
				var _this = this;
				var role = $('#role').text();
				var phone = $('#phone').val();

				if($.trim(phone) === ""){
                    utils.appAlert('手机号码不能为空',function(){
                    	$('#phone').focus();
                    	$('.framework7-root').css({'overflow-y':'scroll'});
                    });
                    return;
				}

				if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
                    utils.appAlert('请输入正确的手机号码',function(){
                    	$('#phone').focus();
                    	$('.framework7-root').css({'overflow-y':'scroll'});
                    });
                    return;
				}

				var data = {
					phone: phone,
					codeType: 8,
					smsType: 2
				};
				utils.initAjax('verify/sendPhoneCode',data,'POST',function(res){
			        utils.appAlert('你正在使用语音获取验证码<br/>请保持手机通畅');
				})
			},*/

			sendVerifyCodeTimer:function(){
				var $time_debounce = $('.verification');
				var _this=this;
				_this.setTimeToDefaut = function(secondsOfInterval) {
                	this.secondLeftOfDelay = secondsOfInterval;
            	};

				var secondsOfInterval = this.secondOfDelay;

				var intervalID = setInterval(function() {
	                secondsOfInterval = secondsOfInterval - 1000;
	                $time_debounce.html(" " + secondsOfInterval / 1000 + " 秒 ")
	                if (secondsOfInterval <= 0) {
	                    clearInterval(intervalID);
	                    $(".verification").removeAttr("disabled");
	                    $time_debounce.html("获取验证码");
	                }
	                _this.setTimeToDefaut(secondsOfInterval);
	            }, 1000);
			},

			submit:function(){
				var role = $('#role').text();
				var phone = $('#phone').val();
				var veryCode = $('#veryCode').val();

				if($.trim(phone) === ""){
                    utils.appAlert('手机号码不能为空',function(){
                    	$('#phone').focus();
                    	$('.framework7-root').css({'overflow-y':'scroll'});
                    });
                    return;
				}

				if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
                    utils.appAlert('请输入正确的手机号码',function(){
                    	$('#phone').focus();
                    	$('.framework7-root').css({'overflow-y':'scroll'});
                    });
                    return;
				}

				var _this=this;
				utils.initAjax('user/isEixt',{
					phone: phone
				},'POST',function(res){
					if(res.msg === "false"){
						utils.appAlert('此用户不存在');
					}else{
						if($.trim(veryCode) === ""){
		                    utils.appAlert('验证码不能为空',function(){
		                    	$('#veryCode').focus();
		                    	$('.framework7-root').css({'overflow-y':'scroll'});
		                    });
		                    return;
						}

						if (_this.submitBtn) {
							return;
						}

						_this.submitBtn = true;
						utils.initAjax('user/forgetPasswod',{
							/*userTyptId: userTyptId,*/
							phone: _this.phone,
							phoneCode: _this.phoneCode
						},'POST',function(res){
							utils.appAlert('新密码已以短信形式下发，<br />请注意查收',function(){
								window.location.href="login.html";
							})	
						},function(res){
							$('body').append('<div class="msg">'+'提交中'+'</div>');
						},function(res){
							$('.msg').hide();
						},function(res){
							_this.submitBtn = false;
							_this.appAlert('系统出现了错误,系统管理员正在修复');
						},function(res){
							_this.submitBtn = false;
							utils.appAlert(res.msg);
						})
					}
				})
				/*var userTyptId;
				if(role.indexOf('会员') === -1){
					userTyptId = _this.customerID;
				}else{
					userTyptId = _this.userID;
				}*/
			}
		}
	})

	return forgetPasswordView
});